package com.tc.zigbee.entity;

import java.util.LinkedList;
import java.util.List;

import com.tc.util.DataUtil;


public class ZNode {
	public byte[] getIeeeAddress() {
		return ieeeAddress;
	}
	public void setIeeeAddress(byte[] ieeeAddress) {
		this.ieeeAddress = ieeeAddress;
	}
	public short getNwkAddress() {
		return nwkAddress;
	}
	public void setNwkAddress(short nwkAddress) {
		this.nwkAddress = nwkAddress;
	}
	public List<Endpoint> getActiveEndpoints() {
		return activeEndpoints;
	}
	public void setActiveEndpoints(List<Endpoint> activeEndpoints) {
		this.activeEndpoints = activeEndpoints;
	}
	byte[] ieeeAddress;
	short nwkAddress;
	List<Endpoint> activeEndpoints = new LinkedList<Endpoint>();
	PowerDescriptor powerDescriptor;
	NodeDescriptor nodeDescriptor;
	ComplexDescriptor complexDescriptor;
	public void setPowerDescriptor(PowerDescriptor powerDescriptor) {
		this.powerDescriptor = powerDescriptor;
	}
	public void setNodeDescriptor(NodeDescriptor nodeDescriptor) {
		this.nodeDescriptor = nodeDescriptor;
	}
	public void setComplexDescriptor(ComplexDescriptor complexDescriptor) {
		this.complexDescriptor = complexDescriptor;
	}
	public PowerDescriptor getPowerDescriptor() {
		return powerDescriptor;
	}
	public NodeDescriptor getNodeDescriptor() {
		return nodeDescriptor;
	}
	public ComplexDescriptor getComplexDescriptor() {
		return complexDescriptor;
	}
	@Override
	public String toString() {

		return this.nwkAddress + "";
	}

	public Endpoint getEndPoint(byte eid){
		for(Endpoint ep : activeEndpoints){
			if(ep.getEndpointId() == eid)
				return ep;
		}
		return null;
	}
	public Endpoint getEndPoint(String eid){
		for(Endpoint ep : activeEndpoints){
			if(DataUtil.hex(ep.getEndpointId()).equals(eid))
				return ep;
		}
		return null;
	}
	public String description() {
		String rst = "";
		rst  = rst + "网络地址：" + this.nwkAddress + "\n";
		rst = rst + "机器地址：" + this.ieeeAddress + "\n";
		if(this.nodeDescriptor != null){
			rst = rst + "节点类型：" + this.nodeDescriptor.logicalType + "\n";
		}
		if(this.powerDescriptor != null){
			rst = rst + "电源状态：" + this.powerDescriptor.CurrentPowerMode + "\n";
		}
		return rst;
	}
}
